home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 October / CMCD1004.ISO / Software / Shareware / Programare / gpssdk / GPS.NET Global Positioning SDK 1.4.6.msi / Data1.cab / EditWaypointForm.vb4 < prev    next >
Encoding:
Text File  |  2004-08-24  |  6.4 KB  |  136 lines

  1. ∩╗┐Imports StormSource.Gps
  2.  
  3. Public Class EditWaypointForm
  4.  
  5.     Private pWaypoint As Waypoint
  6.  
  7.     ' Returns/sets the waypoint being edited by this form
  8.     Public Property Waypoint() As Waypoint
  9.         Get
  10.             Return pWaypoint
  11.         End Get
  12.         Set(ByVal Value As Waypoint)
  13.             ' Remember the waypoint for editing later on
  14.             pWaypoint = Value
  15.  
  16.             ' Update the form with the values
  17.             WaypointName.Text = pWaypoint.Name
  18.             Position.Text = pWaypoint.ToString
  19.             Description.Text = pWaypoint.Description
  20.             Facility.Text = pWaypoint.Facility
  21.             Address.Text = pWaypoint.Address
  22.             City.Text = pWaypoint.City
  23.             State.Text = pWaypoint.State
  24.             Country.Text = pWaypoint.Country
  25.             IntersectingRoad.Text = pWaypoint.IntersectingRoad
  26.  
  27.             ' Update the altitude depth. Are we using the Imperial or Metric system?
  28.             If System.Globalization.RegionInfo.CurrentRegion.IsMetric Then
  29.                 ' Yes. Use meters
  30.                 Altitude.Text = pWaypoint.Altitude.ToMeters.ToString
  31.             Else
  32.                 ' No. Use feet
  33.                 Altitude.Text = pWaypoint.Altitude.ToFeet.ToString
  34.             End If
  35.  
  36.             ' Update the waypoint depth.  Are we using the Imperial or Metric system?
  37.             If System.Globalization.RegionInfo.CurrentRegion.IsMetric Then
  38.                 ' Yes. Use meters
  39.                 Depth.Text = pWaypoint.Depth.ToMeters.ToString
  40.             Else
  41.                 ' No. Use feet
  42.                 Depth.Text = pWaypoint.Depth.ToFeet.ToString
  43.             End If
  44.  
  45.             ' Populate the combo box with the list of available waypoint symbols
  46.             WaypointSymbolComboBox.Items.Clear()
  47.             WaypointSymbolComboBox.Items.AddRange(pWaypoint.Device.GetSymbols)
  48.  
  49.             ' Set the selected item to that of the waypoint
  50.             WaypointSymbolComboBox.SelectedIndex = WaypointSymbolComboBox.FindString(pWaypoint.Symbol.ToString)
  51.  
  52.             ' Populate the color combo box with the list of available waypoint symbols
  53.             WaypointColorComboBox.Items.Clear()
  54.             WaypointColorComboBox.Items.AddRange(pWaypoint.Device.GetColors)
  55.  
  56.             ' Set the selected item to that of the waypoint
  57.             WaypointColorComboBox.SelectedIndex = WaypointColorComboBox.FindString(pWaypoint.Color.ToString)
  58.  
  59.             ' Populate the display mode box with the list of available waypoint symbols
  60.             WaypointDisplayModeComboBox.Items.Clear()
  61.             WaypointDisplayModeComboBox.Items.AddRange(pWaypoint.Device.GetDisplayModes)
  62.  
  63.             ' Set the selected item to that of the waypoint
  64.             WaypointDisplayModeComboBox.SelectedIndex = WaypointDisplayModeComboBox.FindString(pWaypoint.DisplayMode.ToString)
  65.  
  66.             ' Now, enable/disable features based on the capabilities of the device
  67.             Description.Enabled = pWaypoint.Device.SupportsWaypointComment
  68.             Address.Enabled = pWaypoint.Device.SupportsWaypointAddress
  69.             WaypointSymbolComboBox.Enabled = pWaypoint.Device.SupportsWaypointSymbol
  70.             WaypointColorComboBox.Enabled = pWaypoint.Device.SupportsWaypointColor
  71.             WaypointDisplayModeComboBox.Enabled = pWaypoint.Device.SupportsWaypointDisplayMode
  72.             Facility.Enabled = pWaypoint.Device.SupportsWaypointFacility
  73.             Address.Enabled = pWaypoint.Device.SupportsWaypointAddress
  74.             City.Enabled = pWaypoint.Device.SupportsWaypointCity
  75.             State.Enabled = pWaypoint.Device.SupportsWaypointState
  76.             Country.Enabled = pWaypoint.Device.SupportsWaypointCountry
  77.             IntersectingRoad.Enabled = pWaypoint.Device.SupportsWaypointIntersectingRoad
  78.         End Set
  79.     End Property
  80.  
  81.     Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveButton.Click
  82.         Try
  83.             ' Update the waypoint with values from the form
  84.             Waypoint.Name = Me.WaypointName.Text
  85.             ' Update the position
  86.             Dim NewPosition As Position = StormSource.Gps.Position.Parse(Position.Text)
  87.             Waypoint.Latitude = NewPosition.Latitude
  88.             Waypoint.Longitude = NewPosition.Longitude
  89.             ' Update the comment
  90.             Waypoint.Description = Me.Description.Text
  91.             ' Update the symbol
  92.             Waypoint.Symbol = System.Enum.Parse(GetType(WaypointSymbol), WaypointSymbolComboBox.Text)
  93.             ' Update the color
  94.             Waypoint.Color = System.Enum.Parse(GetType(WaypointColor), WaypointColorComboBox.Text)
  95.             ' Update the symbol
  96.             Waypoint.DisplayMode = System.Enum.Parse(GetType(WaypointDisplayMode), WaypointDisplayModeComboBox.Text)
  97.             ' Update the altitude
  98.             Dim NewAltitude As Distance = Distance.Parse(Me.Altitude.Text)
  99.             Waypoint.Altitude = NewAltitude
  100.             ' Update the depth
  101.             Dim NewDepth As Distance = Distance.Parse(Me.Depth.Text)
  102.             Waypoint.Depth = NewDepth
  103.             ' Update the facility
  104.             Waypoint.Facility = Me.Facility.Text
  105.             ' Update the address
  106.             Waypoint.Address = Me.Address.Text
  107.             Waypoint.City = Me.City.Text
  108.             Waypoint.State = Me.State.Text
  109.             Waypoint.Country = Me.Country.Text
  110.             ' Update the intersecting road/intersection
  111.             Waypoint.IntersectingRoad = Me.IntersectingRoad.Text
  112.         Catch ex As Exception
  113.             ' Some error occurred while try to update waypoint information
  114.             MessageBox.Show(ex.Message, "Form Information is Invalid", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  115.             Exit Sub
  116.         End Try
  117.         Try
  118.             ' Save changes to this waypoint
  119.             Waypoint.Save()
  120.             ' Refresh the waypoints collection
  121.             Waypoint.Device.Receiver.Waypoints.Refresh()
  122.             ' Unload this form
  123.             Close()
  124.         Catch ex As Exception
  125.             ' Notify of the problem saving the waypoint
  126.             MessageBox.Show(ex.Message, "Unable to Save Waypoint", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  127.             Exit Sub
  128.         End Try
  129.     End Sub
  130.  
  131.     ' Raised when editing of a waypoint has been cancelled
  132.     Private Sub CancelButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelButton.Click
  133.         Close()
  134.     End Sub
  135. End Class
  136.